//
//  LightningViewController.m
//  LightningReimbursement
//
//  Created by 企点点 on 15/8/4.
//  Copyright (c) 2015年 企点点. All rights reserved.
//

#import "LightningViewController.h"
#import "LeftDrawerViewController.h"
#import "DDMenuController.h"
#import "LSPaoMaView.h"
// 统计视图
#import "StatisticalView.h"
@interface LightningViewController ()<UITableViewDelegate, UITableViewDataSource>

// 点击滚动视图之后的弹出视图
@property (nonatomic, strong) UITableView *popUpView;
// 滚动视图
@property (nonatomic, strong) LSPaoMaView *paoMV;


@end

@implementation LightningViewController

// 懒加载
- (UITableView *)popUpView {
    if (!_popUpView) {
        self.popUpView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain];
        // 设置代理对象
        self.popUpView.dataSource = self;
        self.popUpView.delegate = self;
        self.popUpView.bounces = YES;
    }
    return _popUpView;
}

// 滚动视图
- (LSPaoMaView *)paoMV {
    NSString* text = @"代码改变世界 积累成就自己";
    if (!_paoMV) {
        self.paoMV = [[LSPaoMaView alloc] initWithFrame:CGRectMake(self.view.bounds.size.width / 3, 8, self.view.bounds.size.width * 0.3, 35) title:text];
    }
    return _paoMV;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.navigationController.navigationBar.userInteractionEnabled = YES;
    self.view.backgroundColor = [UIColor colorWithRed:178 / 255.0 green:105 / 255.0 blue:225 / 255.0 alpha:1];
    self.navigationController.navigationBar.barTintColor = [UIColor colorWithRed:178 / 255.0 green:105 / 255.0 blue:225 / 255.0 alpha:1];
    // 调用配置导航条的方法
    [self _setUpNavigationC];
//    // 调用添加分段控制器的方法
    [self _selectInfo];
    // 调用tabBar 的方法
    [self _setUpTabBar];
    NSLog(@"99999999999999999999");
}

// 导航条上的控件
- (void)_setUpNavigationC {
    
    //左边按钮
    UIButton *leftBarButton = [UIButton buttonWithType:UIButtonTypeContactAdd];
    leftBarButton.tintColor = [UIColor whiteColor];
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:leftBarButton];
    // 为button添加响应方法
    [leftBarButton addTarget:self action:@selector(handleLeftButton:) forControlEvents:UIControlEventTouchUpInside];
    
    // 右边按钮
    UIButton *rightButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
    rightButton.tintColor = [UIColor whiteColor];
    
    // 为button添加响应方法
    [rightButton addTarget:self action:@selector(handleRightButton:) forControlEvents:UIControlEventTouchUpInside];
    
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem  alloc] initWithCustomView:rightButton];
    
    // 导航条中间的滚动视图
    [self.navigationController.navigationBar addSubview:self.paoMV];
    
    // 给滚动视图上添加手势
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTap)];
    tap.numberOfTapsRequired = 1;
    [self.paoMV addGestureRecognizer:tap];
    
    // 将弹出视图添加到导航条上
    
    [self.navigationController.navigationBar addSubview:self.popUpView];

    self.popUpView.allowsSelection = YES;
    // 注册单元标识符
    [self.popUpView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"cell"];

}

// 左边按钮的响应方法
- (void)handleLeftButton:(UIButton *)sender {
    DDMenuController *leftDrawer = (DDMenuController *)self.view.window.rootViewController;
    // 弹出左边的抽屉
    [leftDrawer showLeftController:YES];
}
// 右边按钮添加响应方法
- (void)handleRightButton:(UIButton *)sender {
    
}

// 滚动视图的轻拍手势响应方法
- (void)handleTap {
    CGFloat width = self.popUpView.bounds.size.width;
    NSLog(@"5555555555555555");
    if (width) {
        //    // 弹出视图  滚动视图停止
        self.popUpView.frame = CGRectZero;
    } else {
        self.popUpView.frame = CGRectMake(0, 44, self.view.bounds.size.width, 125);
    }
    
}


// 页面上的选择控件
- (void)_selectInfo {
    NSArray *arrayTitle = @[@"总览", @"年", @"月", @"日"];
    UISegmentedControl *segmentC = [[UISegmentedControl alloc]initWithItems:arrayTitle];
    segmentC.frame = CGRectMake(5, 70, self.view.bounds.size.width - 10, 30);
    segmentC.selectedSegmentIndex = 0;
    segmentC.tintColor = [UIColor whiteColor];;
    [self.view addSubview:segmentC];
    [segmentC addTarget:self action:@selector(handleSegmentC:) forControlEvents:UIControlEventValueChanged];

}

// 分段控制器的响应方法
- (void)handleSegmentC:(UISegmentedControl *)sender {
    switch (sender.selectedSegmentIndex) {
        case 0:
        {
            
            break;
        }
        case 1:
        {
            StatisticalView *view = [StatisticalView danliView];
            view.frame = CGRectMake(0, 110, self.view.bounds.size.width, self.view.bounds.size.height - 44);
        }
            break;
        case 2:
        {
            

        }
            
            break;
        case 3:
        {
            

        }
            
            break;
        default:
            break;
    }
}

// tabBar 的配置
- (void)_setUpTabBar {
    UITabBar *tabBar = [[UITabBar alloc] initWithFrame:CGRectMake(0, self.view.bounds.size.height - 44, self.view.bounds.size.width, 44)];
    NSArray *array = @[@"统计", @"审批", @"费用", @"企业"];
    tabBar.barTintColor = [UIColor colorWithRed:178 / 255.0 green:105 / 255.0 blue:225 / 255.0 alpha:1];
    tabBar.barStyle = UIBarStyleDefault;
    for (int i = 0; i < 4; i++) {
        UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(i * 90 + 30, 5, 40, 35)];
        [tabBar addSubview:button];
        button.backgroundColor = [UIColor colorWithRed:178 / 255.0 green:105 / 255.0 blue:225 / 255.0 alpha:1];
        [button setTitle:array[i] forState:UIControlStateNormal];
        [button setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    }
    [self.view addSubview:tabBar];
}

//实现tableView的代理方法
#pragma mark - UITableView的代理方法 -

// 返回行高的方法
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    NSLog(@"1111111111111111");
    return 40;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    NSLog(@"2222222222222222");
    return 3;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell" forIndexPath:indexPath];
    cell.textLabel.text = @"代码改变世界 积累成就自己";
    cell.userInteractionEnabled = YES;
    return cell;
}
//点击单元格响应方法
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    NSLog(@"I miss YOU");
}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
